package com.aura.springbook.service.impl;

import com.aura.springbook.mapper.BookCategoryMapper;
import com.aura.springbook.model.BookCategory;
import com.aura.springbook.service.BookCategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 图书分类服务实现类
 */
@Service
public class BookCategoryServiceImpl extends ServiceImpl<BookCategoryMapper, BookCategory> implements BookCategoryService {

    private static final Logger logger = LoggerFactory.getLogger(BookCategoryServiceImpl.class);

    @Autowired
    private BookCategoryMapper bookCategoryMapper;

    /**
     * 获取所有图书分类
     *
     * @return 图书分类列表
     */
    @Override
    public List<BookCategory> getAllCategories() {
        logger.debug("开始获取所有图书分类");
        
        List<BookCategory> categories = bookCategoryMapper.selectList(null);
        logger.debug("获取所有图书分类完成, 总数: {}", categories.size());
        return categories;
    }

    /**
     * 根据ID获取图书分类
     *
     * @param id 分类ID
     * @return 图书分类信息
     */
    @Override
    public BookCategory getCategoryById(Long id) {
        logger.debug("开始获取图书分类详情, 分类ID: {}", id);
        
        BookCategory category = bookCategoryMapper.selectById(id);
        if (category != null) {
            logger.debug("获取图书分类详情成功, 分类ID: {}, 分类名称: {}", id, category.getName());
        } else {
            logger.warn("获取图书分类详情失败, 分类ID: {} 不存在", id);
        }
        return category;
    }
}